#!/bin/bash
# env_sap_server.sh - version 1.0
#
# Bash script used to specify all the environment variables.
#
# Notes:
# - This has been created from the original Sapphire scripts.
#
# Change logs:
#	1.0: (hicham.x.medkouri@jpmorgan.com), intial version

SRC=$(cd $(dirname "$0"); pwd)
source "${SRC}/ctl_common.sh"

BASE_DIR=`pwd`
HOSTNAME=`hostname`

export SAPPHIRE_USER=`/usr/bin/whoami`;  
export SAPPHIRE_VERSION_STATUS="dev"

export SAPPHIRE_HOME=/cygdrive/c/Work/Projects/Sapphire/services/local-sapphire-server
export SAPPHIRE_CURRENT_VERSION=current
export SAP_SERVER_NAME=topazserver

export QPID_PORT=61616
export JMX_PORT=60606
export SAP_REGION=Emea
export SAPPHIRE_NUMBER_PRICING_SERVER=1
export SAPPHIRE_NUMBER_RISK_SERVER=1
export SAPPHIRE_MACHINE_LOCATION="DEV"
export USERNAME=BLUEDEV
export QPID_MAX_PREFETCH=1

export TOPAZ_SAPPHIRE_SERVICES=TopazDevServer2_QPID

###########################
# non editable parameters #
###########################

# OS specific support.
cygwin=false
darwin=false
os400=false
case "`uname`" in
CYGWIN*) cygwin=true;;
Darwin*) darwin=true;;
OS400*) os400=true;;
esac

export SAPPHIRE_LOG_DIR=${SAPPHIRE_HOME}/logs
export BLUE_USER_DIR=${SAPPHIRE_LOG_DIR}
export LIBDIR=${SAPPHIRE_HOME}/sapphire-packages/${SAPPHIRE_CURRENT_VERSION}/lib
export DLLSDIR=${SAPPHIRE_HOME}/sapphire-packages/${SAPPHIRE_CURRENT_VERSION}/config/global/dlls
export SAPPHIRE_APP_DIR=${SAPPHIRE_HOME}/apps
export SAPPHIRE_DATA_DIR=${SAPPHIRE_HOME}/data
export SAPPHIRE_CONFIG_DIR=${SAPPHIRE_HOME}/config
export SAPPHIRE_RUNTIME_DIR=${SAPPHIRE_HOME}/runtime
export ALIB_KEY=${SAPPHIRE_CONFIG_DIR}/alibkeys;

export CBB_CLIENT_LIB=${SAPPHIRE_HOME}/SouthBeach4.6
export SB_HOME=${CBB_CLIENT_LIB}/client/lib
export EGO_CONFDIR=${CBB_CLIENT_LIB}/SOAM/conf
export SOAM_HOME=${CBB_CLIENT_LIB}/SOAM/conf
export SOAM_LIB=${CBB_CLIENT_LIB}/SOAM/lib

export LOG4J_LOC=${SAPPHIRE_CONFIG_DIR}/log4j.xml
#export SAPPHIRE_VERSION_PROPERTIES="${SAP_REGION}ServerNonProd"
#export SAPPHIRE_VERSION_PROPERTIES_RISK="${SAP_REGION}RiskServerNonProd"
export SAPPHIRE_VERSION_PROPERTIES=LocalTopazServer
export SAPPHIRE_VERSION_PROPERTIES_RISK=LocalTopazServer

export SAPPHIRE_RUNNING_SERVERS_FILE=${SAPPHIRE_RUNTIME_DIR}/server.pid
export SAPPHIRE_LOC=${SAPPHIRE_HOME}/sapphire-resources/${SAPPHIRE_CURRENT_VERSION}
export BLUE_VERSION_PATH="${SAPPHIRE_LOC}/config/servers/blueversion"
export SAPPHIRE_SCRIPTS_LOC=${SAPPHIRE_LOC}/config/servers
export SAPPHIRE_GEMFIRE_PROP_FILE=${SAPPHIRE_LOC}/config/global/cbb/gemfire.properties
export SAPPHIRE_GEMFIRE_CACHE_FILE="${SAPPHIRE_LOC}/config/global/cbb/cache_prod_$(tr [A-Z] [a-z] <<< "$SAP_REGION").xml"

export SAP_LOG4J_LOC_PREFIX=${SAPPHIRE_LOG_DIR}

export SAPPHIRE_QUEUE_PREFIX="DEV"
export SAPPHIRE_LIVE_QUEUE_PREFIX="_Live"
export SAPPHIRE_CLOSE_QUEUE_PREFIX="_Close"
export SAPPHIRE_SOD_QUEUE_PREFIX="_SOD"
export SAPPHIRE_PV_QUEUE_PREFIX="_PV"
export SAPPHIRE_RISK_QUEUE_SUFFIX="_RiskQ"

export SAPPHIRE_LIVE_RISK_QUEUE=`echo "${SAPPHIRE_QUEUE_PREFIX}"{1..1}${SAPPHIRE_LIVE_QUEUE_PREFIX}${SAPPHIRE_RISK_QUEUE_SUFFIX},`
export SAPPHIRE_CLOSE_RISK_QUEUE=`echo "${SAPPHIRE_QUEUE_PREFIX}"{1..1}${SAPPHIRE_CLOSE_QUEUE_PREFIX}${SAPPHIRE_RISK_QUEUE_SUFFIX},`
export SAPPHIRE_SOD_RISK_QUEUE=`echo "${SAPPHIRE_QUEUE_PREFIX}"{1..1}${SAPPHIRE_SOD_QUEUE_PREFIX}${SAPPHIRE_RISK_QUEUE_SUFFIX},`
export SAPPHIRE_PV_RISK_QUEUE=`echo "${SAPPHIRE_QUEUE_PREFIX}"{1..1}${SAPPHIRE_PV_QUEUE_PREFIX}${SAPPHIRE_RISK_QUEUE_SUFFIX},`
export SAPPHIRE_COMPLETE_RISK_QUEUE="${SAPPHIRE_LIVE_RISK_QUEUE},${SAPPHIRE_CLOSE_RISK_QUEUE},${SAPPHIRE_SOD_RISK_QUEUE},${SAPPHIRE_PV_RISK_QUEUE}"
#export SAPPHIRE_COMPLETE_RISK_QUEUE="${SAPPHIRE_SOD_RISK_QUEUE}"
export SAPPHIRE_RISK_QUEUE=`echo ${SAPPHIRE_COMPLETE_RISK_QUEUE} | sed 's/ //g' | sed 's/,,/,/g' | sed 's/\(.*\)./\1/g'`

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/lwpi:${SOAM_LIB}:${SB_HOME}:${SOAM_HOME}:${DLLSDIR}

export JAVA_OPTS="${JAVA_OPTS} -server"
export JAVA_OPTS="${JAVA_OPTS} -Xss2m"
export JAVA_OPTS="${JAVA_OPTS} -Xms128m"
export JAVA_OPTS="${JAVA_OPTS} -Xmx256m"
export JAVA_OPTS="${JAVA_OPTS} -Djava.library.path=$LD_LIBRARY_PATH"
#export JAVA_OPTS="${JAVA_OPTS} -Dlog4j.configuration=${LOG4J_LOC}" 
export JAVA_OPTS="${JAVA_OPTS} -Dinstance=${INSTANCE}"
export JAVA_OPTS="${JAVA_OPTS} -Dpid=$$"
export JAVA_OPTS="${JAVA_OPTS} -DjmxName=${USERNAME}"
#export JAVA_OPTS="${JAVA_OPTS} -DtopazServices=${TOPAZ_SAPPHIRE_SERVICES}"
export JAVA_OPTS="${JAVA_OPTS} -Dmax_prefetch=${QPID_MAX_PREFETCH}"
export JAVA_OPTS="${JAVA_OPTS} -DUserDefinedBlueVersion=${SAPPHIRE_VERSION_PROPERTIES}"
export JAVA_OPTS="${JAVA_OPTS} -DmachineLocation=${SAPPHIRE_MACHINE_LOCATION}"
#export JAVA_OPTS="${JAVA_OPTS} -DSAP_LOG4J_LOC_PREFIX=${SAP_LOG4J_LOC_PREFIX}"
export JAVA_OPTS="${JAVA_OPTS} -DTransportPort=${QPID_PORT}"
export JAVA_OPTS="${JAVA_OPTS} -Dxsd.validation=false"
export JAVA_OPTS="${JAVA_OPTS} -Dsun.rmi.dgc.client.gcInterval=86480000"
export JAVA_OPTS="${JAVA_OPTS} -Dsun.rmi.dgc.server.gcInterval=86480000"

export GC_OPTS="-XX:+UsePerfData"
export GC_OPTS="${GC_OPTS} -XX:+UseParNewGC"
export GC_OPTS="${GC_OPTS} -XX:ParallelGCThreads=2"
export GC_OPTS="${GC_OPTS} -XX:+DisableExplicitGC"
export GC_OPTS="${GC_OPTS} -XX:TargetSurvivorRatio=95"
export GC_OPTS="${GC_OPTS} -XX:NewSize=64m"
export GC_OPTS="${GC_OPTS} -XX:MaxNewSize=128m"
export GC_OPTS="${GC_OPTS} -XX:SurvivorRatio=6"
export GC_OPTS="${GC_OPTS} -XX:PermSize=32m"
export GC_OPTS="${GC_OPTS} -XX:MaxPermSize=128m"

#export JAVA_CBB_OPTS="-DgemfirePropertyFile=${SAPPHIRE_GEMFIRE_PROP_FILE} -Dgemfire.cache-xml-file=${SAPPHIRE_GEMFIRE_CACHE_FILE} -DUseCBBForCurveTweaks=false"

# JPDA variables used to remotely debug sapphire, the server must be launched using start_jpda option
export JPDA_ADDRESS=8787
export JPDA_TRANSPORT=dt_socket
export JPDA_SUSPEND=y

if [ "$_DEBUG" == "true" ]; then
	_log SAPPHIRE_USER=$SAPPHIRE_USER
	_log SAPPHIRE_VERSION_STATUS=$SAPPHIRE_VERSION_STATUS
	_log SAPPHIRE_HOME=$SAPPHIRE_HOME
	_log SAPPHIRE_CURRENT_VERSION=$SAPPHIRE_CURRENT_VERSION
	_log SAP_SERVER_NAME=$SAP_SERVER_NAME
	_log
	_log QPID_PORT=$QPID_PORT
	_log JMX_PORT=$JMX_PORT
	_log SAPPHIRE_NUMBER_PRICING_SERVER=$SAPPHIRE_NUMBER_PRICING_SERVER
	_log SAPPHIRE_NUMBER_RISK_SERVER=$SAPPHIRE_NUMBER_RISK_SERVER
	_log SAPPHIRE_MACHINE_LOCATION=$SAPPHIRE_MACHINE_LOCATION
	_log USERNAME=$USERNAME
	_log QPID_MAX_PREFETCH=$QPID_MAX_PREFETCH
	_log
	_log TOPAZ_SAPPHIRE_SERVICES=$TOPAZ_SAPPHIRE_SERVICES
	_log
	_log SAPPHIRE_LOG_DIR=$SAPPHIRE_LOG_DIR
	_log BLUE_USER_DIR=$BLUE_USER_DIR
	_log LIBDIR=$LIBDIR
	_log DLLSDIR=$DLLSDIR
	_log SAPPHIRE_APP_DIR=$SAPPHIRE_APP_DIR
	_log SAPPHIRE_DATA_DIR=$SAPPHIRE_DATA_DIR
	_log SAPPHIRE_CONFIG_DIR=$SAPPHIRE_CONFIG_DIR
	_log SAPPHIRE_RUNTIME_DIR=$SAPPHIRE_RUNTIME_DIR
	_log ALIB_KEY=$ALIB_KEY
	_log
	_log CBB_CLIENT_LIB=$CBB_CLIENT_LIB
	_log SB_HOME=$SB_HOME
	_log EGO_CONFDIR=$EGO_CONFDIR
	_log SOAM_HOME=$SOAM_HOME
	_log SOAM_LIB=$SOAM_LIB
	_log
	_log LOG4J_LOC=$LOG4J_LOC
	_log SAPPHIRE_VERSION_PROPERTIES=$SAPPHIRE_VERSION_PROPERTIES
	_log SAPPHIRE_VERSION_PROPERTIES_RISK=$SAPPHIRE_VERSION_PROPERTIES_RISK
	_log
	_log SAPPHIRE_RUNNING_SERVERS_FILE=$SAPPHIRE_RUNNING_SERVERS_FILE
	_log SAPPHIRE_LOC=$SAPPHIRE_LOC
	_log BLUE_VERSION_PATH=$BLUE_VERSION_PATH
	_log SAPPHIRE_SCRIPTS_LOC=$SAPPHIRE_SCRIPTS_LOC
	_log SAPPHIRE_GEMFIRE_PROP_FILE=$SAPPHIRE_GEMFIRE_PROP_FILE
	_log SAPPHIRE_GEMFIRE_CACHE_FILE=$SAPPHIRE_GEMFIRE_CACHE_FILE
	_log
	_log SAP_LOG4J_LOC_PREFIX=$SAP_LOG4J_LOC_PREFIX
	_log
	_log SAPPHIRE_QUEUE_PREFIX=$SAPPHIRE_QUEUE_PREFIX
	_log SAPPHIRE_LIVE_QUEUE_PREFIX=$SAPPHIRE_LIVE_QUEUE_PREFIX
	_log SAPPHIRE_CLOSE_QUEUE_PREFIX=$SAPPHIRE_CLOSE_QUEUE_PREFIX
	_log SAPPHIRE_SOD_QUEUE_PREFIX=$SAPPHIRE_SOD_QUEUE_PREFIX
	_log SAPPHIRE_RISK_QUEUE_SUFFIX=$SAPPHIRE_RISK_QUEUE_SUFFIX
	_log
	_log SAPPHIRE_LIVE_RISK_QUEUE=$SAPPHIRE_LIVE_RISK_QUEUE
	_log SAPPHIRE_CLOSE_RISK_QUEUE=$SAPPHIRE_CLOSE_RISK_QUEUE
	_log SAPPHIRE_SOD_RISK_QUEUE=$SAPPHIRE_SOD_RISK_QUEUE
	_log SAPPHIRE_COMPLETE_RISK_QUEUE=$SAPPHIRE_COMPLETE_RISK_QUEUE
	_log SAPPHIRE_RISK_QUEUE=$SAPPHIRE_RISK_QUEUE
	_log
	_log LD_LIBRARY_PATH=$LD_LIBRARY_PATH
	_log
	_log JAVA_OPTS=$JAVA_OPTS
	_log GC_OPTS=$GC_OPTS
	_log JAVA_CBB_OPTS=$JAVA_CBB_OPTS
fi
